//
//  ScanBCViewController.m
//  NewPro
//
//  Created by RYX on 2018/10/24.
//  Copyright © 2018年 何荧红. All rights reserved.
//

#import "ScanBCViewController.h"
#import "WYIDScanViewController.h"
#import "ScanIdList.h"
#import "ScanBandModel.h"
#import "ScanOverViewController.h"
#import "RealNameParametersModel.h"

@interface ScanBCViewController ()
{
    
    __weak IBOutlet UIImageView *bandImg;
    
}

@property (nonatomic,weak) UIButton *btn;

@end

@implementation ScanBCViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setNavBarWithTitle:@"实名认证"];
}

- (IBAction)onScanBtn:(UIButton *)sender {
    
    sender.enabled = NO;
    
    _btn = sender;
    
    WYIDScanViewController *VC = [[WYIDScanViewController alloc] initWithCarInfo: CardIDBank];
    
    MJWeakSelf
    [VC scanDidFinishCarInfo:^(CardType status, WYScanResultModel *scanModel) {
        
        sender.enabled = NO;
        
        NSString *str = [scanModel.bankNumber stringByReplacingOccurrencesOfString:@" " withString:@""];
        
        [ScanIdList sharedInstance].scanBandModel.bankNumber = str;
        [ScanIdList sharedInstance].scanBandModel.bankName = scanModel.bankName;
        [ScanIdList sharedInstance].scanBandModel.bankImage = scanModel.bankImage;

        self->bandImg.image = scanModel.bankImage;
        
        [ScanIdList sharedInstance].realNameModel.bankFrontImgData = [ImgManager imageToString:scanModel.bankImage];
        [ScanIdList sharedInstance].realNameModel.bank = scanModel.bankName;
        [ScanIdList sharedInstance].realNameModel.bankno = scanModel.bankNumber;
        
        [SVPManager showSuccessWithTitle:@"   扫 描 成 功   "];
        
        //GCD延迟
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            ScanOverViewController *VC = [[ScanOverViewController alloc] init];
            [weakSelf.navigationController pushViewController:VC animated:YES];
            
        });
    }];
    
    [VC scanFailure:^{
        
        sender.enabled = YES;
    }];
    
    [self.navigationController pushViewController:VC animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
    
    _btn.enabled = YES;
}
@end
